<template>
  <div>
    <van-uploader :after-read="uploadImg"></van-uploader>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "Index",
  data() {
    return {};
  },
  methods: {
    uploadImg(file) {
      let formData = new FormData();
      formData.append("file", file.file);
      console.log(formData);
      //将file转成formData格式
      axios
        .post("http://shop.bluej.cn/api/update", formData)
        .then((data) => {
          //data.result.path就是图片url
          console.log(data.data.result.path);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
